package org.xserver.component.extension.filter.condition;

import org.xserver.component.core.interfaces.InterfaceMeta;
import org.xserver.component.extension.filter.FilterConfig;

/**
 * The {@code ConditionResolver} is use regular expression to check the
 * interfaces key.
 * 
 * <h3>Example:</h3>
 * <ul>
 * <li>The regex '<strong>/user/*</strong>' represents for the something about
 * <Strong>user add, delete</strong>. And <strong>/user/list</strong> is a
 * interfaces mounted on server, it can match the condition, and will go to
 * relevant filter(s).</li>
 * <li>The regex '<strong>/* /*Delete</strong>' represents for anything about
 * delete operation. And <strong>/system/menuDelete</strong> is a system manage
 * to delete some menu or something like this. so it can pass the regex.</li>
 * </ul>
 * 
 * @author idoldefine
 * @since 2015/10/31
 * 
 */
public class RegexPathConditionResolver implements ConditionResovler {

	/**
	 * If the interfaces request path match configured conditions, return true,
	 * else none of conditions cannot be matched, return false.
	 */
	@Override
	public boolean checkCondition(InterfaceMeta interfaceMeta,
			FilterConfig filterConfig) {
		/*List<FilterCondition> conditions = filterConfig.getFilterConditions();
		for (FilterCondition condition : conditions) {
			String key = StringUtil.toLowerCaseAtIndex(interfaceMeta.getClazz()
					.getSimpleName(), 0)
					+ DEFAULT_INTERFACE_SPLIT
					+ interfaceMeta.getMethod().getName();

			// TODO compile and match can improve performance
			if (Pattern.matches(condition.getPath(), key)) {
				return true;
			}
		}*/

		return false;
	}
}
